﻿using System.ComponentModel.DataAnnotations;
using System.Collections.Generic;
using System.Linq;

namespace GameSchoolApplication.Models
{
	public class Person : LogOnModel
	{
		[Key]
		public int Id			{ get; set; }
        
		[Display(Name = "Nafn")]
		public string Name		{ get; set; }
        
		[Display(Name = "Netfang")]
		public string Email		{ get; set; }
		
		//[Display(Name = "Hópur")]
		//[Required]
		public string Group		{ get; set; }
		/*public int StudentId	{ get; set; }
		public int TeacherId	{ get; set; }
		public int SupervisorId { get; set; }*/

        public virtual ICollection<GameInstructor> GameInstructors { get; set; }
        public virtual ICollection<StudentPoints> Enrollments { get; set; }
        public virtual ICollection<StudentLevelPoints> LevelParticipations { get; set; }

        public IEnumerable<StudentPoints> OpenEnrollments
        {
            get
            {
                return Enrollments.Where(e => e.Game.IsOpen);
            }
        }

        public IEnumerable<StudentLevelPoints> CurrentLevels
        {
            get
            {
                return OpenEnrollments.Select(e => e.CurrentLevel).Where(l => l != null);
            }
        }

        public IEnumerable<Announcement> LatestAnnouncements
        {
            get
            {
                return OpenEnrollments.SelectMany(e => e.Game.Announcements).OrderByDescending(a => a.Id).Take(5);
            }
        }

        public IEnumerable<Announcement> AllAnnouncements
        {
            get
            {
                return OpenEnrollments.SelectMany(e => e.Game.Announcements);
            }
        }
	}

}